package com.digitalchina.lxnsy.api;

import android.app.Activity;
import android.os.Handler;

import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.constant.URL;
import com.digitalchina.lxnsy.toolkit.OkHttpUtil;
import com.digitalchina.lxnsy.xml.UserXML;
import com.lzy.okhttputils.model.HttpParams;

/**
 * ================================================
 * 项目名称：YLCloud
 * 类描述：
 * 包名：com.digitalchina.bigdata.api
 * 创建人：郑皓
 * 创建时间：2016/9/28 14:45
 * 修改备注：
 * ================================================
 */
public class BusinessRongIM {

    /**
     * 服务端获取融云token
     *
     * @param activity
     * @param userId
     * @param username
     * @param handler
     */
    public static void getUserRCToken(Activity activity, String userId, String username, Handler handler) {
        HttpParams params = new HttpParams();
        params.put("userId", userId);
        params.put("username", username);
        params.put("tokenStatus", "1");
        OkHttpUtil.post(activity, URL.URL_GET_USER_RC_TOKEN, "", params, handler,
                MSG.MSG_GET_USER_RC_TOKEN_SUCCESS, MSG.MSG_GET_USER_RC_TOKEN_FIELD);
    }

    /**
     * 添加文字聊天记录
     *
     * @param activity
     * @param toUser
     * @param content
     * @param handler
     */
    public static void addMessageInfo(Activity activity, String toUser, String content, Handler handler) {
        HttpParams params = new HttpParams();
        params.put("sendUser", UserXML.getUserId(activity));
        params.put("toUser", toUser);
        params.put("content", content);
        params.put("msgType", "1");
        OkHttpUtil.post(activity, URL.URL_ADD_MESSAGE_INFO, "", params, handler,
                MSG.MSG_ADD_MESSAGE_INFO_SUCCESS, MSG.MSG_ADD_MESSAGE_INFO_FIELD);
    }

    /**
     * 添加图片聊天记录
     *
     * @param activity
     * @param toUser
     * @param content
     * @param handler
     */
    public static void addImageMessageInfo(Activity activity, String toUser, String content, Handler handler) {
        HttpParams params = new HttpParams();
        params.put("sendUser", UserXML.getUserId(activity));
        params.put("toUser", toUser);
        params.put("content", content);
        params.put("msgType", "2");
        OkHttpUtil.post(activity, URL.URL_ADD_MESSAGE_INFO, "", params, handler,
                MSG.MSG_ADD_MESSAGE_INFO_SUCCESS, MSG.MSG_ADD_MESSAGE_INFO_FIELD);
    }

    /**
     * 添加语音消息聊天记录
     *
     * @param activity
     * @param toUser
     * @param content
     * @param handler
     */
    public static void addVoiceMessageInfo(Activity activity, String toUser, String content, Handler handler) {
        HttpParams params = new HttpParams();
        params.put("sendUser", UserXML.getUserId(activity));
        params.put("toUser", toUser);
        params.put("content", content);
        params.put("msgType", "3");
        OkHttpUtil.post(activity, URL.URL_ADD_MESSAGE_INFO, "", params, handler,
                MSG.MSG_ADD_MESSAGE_INFO_SUCCESS, MSG.MSG_ADD_MESSAGE_INFO_FIELD);
    }

    /**
     * 获取会话用户列表
     *
     * @param activity
     * @param handler
     */
    public static void getConversationList(Activity activity, Handler handler) {
        HttpParams params = new HttpParams();
        params.put("sendUser", UserXML.getUserId(activity));
        OkHttpUtil.post(activity, URL.URL_GET_CONVERSATION_LIST, "", params, handler,
                MSG.MSG_GET_CONVERSATION_LIST_SUCCESS, MSG.MSG_GET_CONVERSATION_LIST_FIELD);
    }

}
